package com.habo.service.impl;

import com.habo.dao.WeiBoMapper;
import com.habo.entity.WeiBo;
import com.habo.service.WeiBoService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * Created by jiuyou on 2017/3/27 0027.
 */
@Service
public class WeiBoServiceImpl implements WeiBoService {
    @Resource
    private WeiBoMapper weiBoMapper;

    /**
     * 发布微博
     * @param weiBo
     */
    public void addWeiBo(WeiBo weiBo) {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd--hh--mm--ss");
        Date date=new Date();//设置发送时间为当前时间
        String str=df.format(date);
        weiBo.setWbtime(date);
        weiBo.setWbtop(0);//设置置顶状态默认为0，不置顶
        weiBo.setWbpermission(0);//设置浏览权限默认为0，对外公开
        weiBo.setWbpraise(0);//设置点赞数默认为0
        weiBoMapper.addWeiBo(weiBo);
    }

    /**
     * 查找全部微博
     * @return
     */
    public List<WeiBo> findAllWeiBo() {
        return weiBoMapper.findAllWeiBo();
    }

    /**
     * 通过用户uid来查找微博
     * @param uid
     * @return
     */
    public List<WeiBo> findWeiBoByU_id(String uid) {
        return weiBoMapper.findWeiBoByU_id(uid);
    }

    public WeiBo findByWB_id(int wbid) {
        return weiBoMapper.findByWB_id(wbid);
    }
}
